import React from 'react';
import { inject, observer } from 'mobx-react';
import { Button } from 'antd';
import { WeaDialog,WeaLocaleProvider} from 'ecCom';
import TaskDetail from './TaskDetail';
const getLabel = WeaLocaleProvider.getLabel;
@inject('taskDetailDialogStore')
@observer
export default class TaskDetailDialog extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            detailKey:this.props.detailKey,
        }
    }

    componentWillMount() {//一些初始化请求

    }

    componentWillReceiveProps(newProps){
        if(this.props.locationkey!=newProps.locationkey){
            this.setState({detailKey:newProps.detailKey});
        }
    }

    getButton = ()=>{
        let buttonsCreate = [
            (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@c02c2k@close`} type="ghost" onClick={this.onlyClose}>{getLabel(309,'关闭')}</Button>)
        ];
        return buttonsCreate;
    }
    onlyClose=()=>{
        this.props.onlyClose && this.props.onlyClose();
    }
    onDialogSuccess(key,type,optparams){
        if(type){
            if(typeof this.props.dialogCallBack === "function"){
               this.props.dialogCallBack(optparams);
            }
        }else{
            this.setState({detailKey:key});
        }
    }
    render() {
        const {style,visable,taskDetailDialogStore} = this.props;
        const {detailKey} = this.state;
        let _height = style.height?style.height-75:window.innerHeight;
        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@qg6ojj`}
                visible={visable}
                title={getLabel(508789,'任务详情')}
                icon="icon-coms-Journal"
                iconBgcolor="#7734FF"
                className="createWorkPlan"
                buttons={this.getButton()}
                style={style}
                closable={true}
                onCancel={this.onlyClose}
            >
               <TaskDetail ecId={`${this && this.props && this.props.ecId || ''}_TaskDetail@dfdbk4`} isshow={true} onDialogSuccess={(key,type,optparams)=>this.onDialogSuccess(key,type,optparams)} detailKey={detailKey} taskDetailStore={taskDetailDialogStore} _height={_height} isshow={true} />
            </WeaDialog>
        )
    }
};